package cn.fay.chapter11;

import java.util.LinkedList;
import java.util.Random;


public class LinkedListFeatures {

	
	public static void main(String[] args) {
		LinkedList<Integer> list=new LinkedList<Integer>();
		Random random=new Random(47);
		for (int i = 0; i < 15; i++) 
			list.add(random.nextInt(100));
		System.out.println(list);
		
		//列表为空是抛出NoSuchElementException
		System.out.println("list.getFirst(): "+list.getFirst());
		System.out.println("list.element():"+list.element() );
		//列表为空是返回null，这是它和上面两个的唯一差别
		System.out.println("list.peek(): "+list.peek());
		
		System.out.println("-----------------");
		
		//列表为空是抛出NoSuchElementException
		System.out.println("list.remove(): "+list.remove());
		System.out.println("list.removeFirst(): "+list.removeFirst());
		//列表为空是返回null，这是它和上面两个的唯一差别
		System.out.println("list.poll(): "+list.poll());
		
		list.add(77);
		System.out.println("list.add() :"+list);
		list.addFirst(78);
		System.out.println("list.addFirst(): "+list);
		list.addLast(79);
		System.out.println("list.addLast(): "+list);
		list.offer(80);
		System.out.println("list.offer(): "+list);
		list.removeLast();
		System.out.println("list.removeLast(): "+list);
		
	}

}
